package com.my.zidingyikongjian.view.two;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.view.View;

/**
 * 项目名称：圆角矩形路径
 * 创建人：mwb
 * 创建时间：2018/7/10 14:25
 */

public class DrawRoundRectRoute extends View {
    private int flag = -1;

    public DrawRoundRectRoute(Context context, int flag) {
        super(context);
        this.flag = flag;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setStrokeWidth(5);
        paint.setStyle(Paint.Style.STROKE); // 描边
        paint.setColor(Color.BLUE); // 颜色

        if (flag == 0) { // 圆角矩形
            Path path = new Path();
            RectF rect1 = new RectF(50, 50, 240, 200);
            path.addRoundRect(rect1, 10, 15, Path.Direction.CCW); // 逆时针
            /**
             * float[] radii：必须传入8个数值，分四组，
             * 分别对应每个角所使用的椭圆的横轴半径和纵轴半径，
             * 如｛x1,y1,x2,y2,x3,y3,x4,y4｝，其中，
             * x1,y1对应第一个角的（左上角）用来产生圆角的椭圆的横轴半径和纵轴半径，其它类推……
             */
            RectF rect2 = new RectF(290, 50, 480, 200);
            float radii[] = {10, 15, 20, 25, 30, 35, 40, 45};
            path.addRoundRect(rect2, radii, Path.Direction.CCW);

            canvas.drawPath(path, paint);
        } else if (flag == 1) { // 圆形路径
            Path path = new Path();
            path.addCircle(200, 200, 100, Path.Direction.CCW); // 逆时针 半径为100
            canvas.drawPath(path, paint);
        } else if (flag == 2) { // 椭圆
            Path path = new Path();
            RectF rectF = new RectF(50, 50, 240, 200);
            path.addOval(rectF, Path.Direction.CCW);
            canvas.drawPath(path, paint);
        } else if (flag == 3) { // 弧
            Path path = new Path();
            RectF rectF = new RectF(50, 50, 240, 200);
            path.addArc(rectF, 0, 100);
            canvas.drawPath(path, paint);
        }
    }
}
